Skip to content

Validate task type before model upload#457

Merged
leeclemnet merged 2 commits intomainfrom
fix/task-type-validation
Apr 21, 2026
Merged

Validate task type before model upload#457
leeclemnet merged 2 commits intomainfrom
fix/task-type-validation

Conversation

@leeclemnet
Copy link
Copy Markdown
Contributor

@leeclemnet leeclemnet commented Apr 17, 2026

Summary

Uploading a seg .pt with model_type="yolov11" used to succeed silently then crash at inference because models could be registered with an incorrect task type. Same for rfdetr detect/seg mismatches. Adds two client-side checks:

  1. .ptmodel_type reconciliation in model_processor.process():
    • YOLO: detects task from Ultralytics class name. Auto-appends the missing suffix when user omitted it; raises on conflict.
    • RF-DETR: detects task from checkpoint["model_name"] (same field rf-detr's loader uses). Raises on conflict.
  2. model_type ↔ project type cross-check in Version.deploy().

Also adds canonical TASK_* constants to config.py.

Test plan

  • New unit tests
  • Upload yolov11 OD weights downloaded from roboflow to IS project blocked (versionless + versioned)
roboflow model upload -m ~/data/weight-upload-test/yolov11 -t yolov11s -f weights.pt -p bouldering-holds-9wavr-wrfb4 -n yolov11
loading Roboflow workspace...
Error: Project 'bouldering-holds-9wavr-wrfb4' is type 'instance-segmentation' (task 'seg') but model_type 'yolov11s' implies task 'det'.

roboflow model upload -m ~/data/weight-upload-test/yolov11 -t yolov11s -f weights.pt -p bouldering-holds-9wavr-wrfb4 -n yolov11 -v 2
loading Roboflow workspace...
loading Roboflow project...
Error: Project 'bouldering-holds-9wavr-wrfb4' is type 'instance-segmentation' (task 'seg') but model_type 'yolov11s' implies task 'det'.

roboflow model upload -m ~/data/weight-upload-test/yolov11 -t yolov11s-seg -f weights.pt -p bouldering-holds-9wavr-wrfb4 -n yolov11
loading Roboflow workspace...
Error: model_type 'yolov11s-seg' implies task 'seg' but the .pt file is a 'det' checkpoint. Use a matching model_type.

roboflow model upload -m ~/data/weight-upload-test/yolov11 -t yolov11s-seg -f weights.pt -p bouldering-holds-9wavr-wrfb4 -n yolov11 -v 2
loading Roboflow workspace...
loading Roboflow project...
Error: model_type 'yolov11s-seg' implies task 'seg' but the .pt file is a 'det' checkpoint. Use a matching model_type.
  • Upload rfdetr IS weights downloaded from roboflow to OD project blocked (versionless + versioned)
roboflow model upload -m ~/data/weight-upload-test/rfdetr-nano-seg -t rfdetr-seg-nano -f weights.pt -p sign-language-sokdr-j1ne3 -n rfdetr-nano-seg
loading Roboflow workspace...
Error: Project 'sign-language-sokdr-j1ne3' is type 'object-detection' (task 'det') but model_type 'rfdetr-seg-nano' implies task 'seg'.

roboflow model upload -m ~/data/weight-upload-test/rfdetr-nano-seg -t rfdetr-seg-nano -f weights.pt -p sign-language-sokdr-j1ne3 -n rfdetr-nano-seg -v 7
loading Roboflow workspace...
loading Roboflow project...
Error: Project 'sign-language-sokdr-j1ne3' is type 'object-detection' (task 'det') but model_type 'rfdetr-seg-nano' implies task 'seg'.

roboflow model upload -m ~/data/weight-upload-test/rfdetr-nano-seg -t rfdetr-nano -f weights.pt -p sign-language-sokdr-j1ne3 -n rfdetr-nano-seg
loading Roboflow workspace...
Error: model_type 'rfdetr-nano' implies task 'det' but the .pt is a 'seg' rfdetr checkpoint. Use a matching model_type.

roboflow model upload -m ~/data/weight-upload-test/rfdetr-nano-seg -t rfdetr-nano -f weights.pt -p sign-language-sokdr-j1ne3 -n rfdetr-nano-seg -v 7
loading Roboflow workspace...
loading Roboflow project...
Error: model_type 'rfdetr-nano' implies task 'det' but the .pt is a 'seg' rfdetr checkpoint. Use a matching model_type.

🤖 Generated with Claude Code

@leeclemnet leeclemnet marked this pull request as draft April 17, 2026 16:11
@leeclemnet leeclemnet force-pushed the fix/task-type-validation branch 9 times, most recently from 7e3a2bf to 899ce06 Compare April 21, 2026 14:01
@leeclemnet leeclemnet force-pushed the fix/task-type-validation branch from 899ce06 to 120289b Compare April 21, 2026 14:06
@leeclemnet leeclemnet marked this pull request as ready for review April 21, 2026 14:06
Copy link
Copy Markdown
Contributor

@probicheaux probicheaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@leeclemnet leeclemnet merged commit da3fa95 into main Apr 21, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants